package org.nowcoder.huawei.c100;

/**
 * 53:分割均衡字符串
 */
public class HC053 {
    public static void main(String[] args) {
        System.out.println(new HC053().balancedStringSplit("RLRRLLRLRL"));
    }

    public int balancedStringSplit(String s) {
        if (s.length() == 2) {
            return 1;
        }
        int count = 0, l = 1;
        char c = s.charAt(0);
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == c) {
                l++;
            } else {
                l--;
                if (l == 0) {
                    count++;
                    if (i < s.length() - 1) {
                        c = s.charAt(++i);
                        l = 1;
                    } else {
                        break;
                    }
                }
            }
        }
        return count;
    }
}
